<?php if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class login extends CI_Controller {
    public $data = array('pesan' => '' );
        public function __construct() {
            parent::__construct();
            $this->load->helper('form');
            $this->load->library('form_validation');
            $this->load->model('Login_Model', 'login', TRUE); }
    
    public function index() {
        if ($this->session->userdata('login') == TRUE) {
            redirect('absen'); }
        else {
            if($this->login->validasi()) {
                if($this->login->cek_user()) {
                    redirect('absen') ; }
                else {
                    $this->data['pesan'] = ' Username atau password yang dimasukkan salah' ;
                    $this->load->view('login/login_form', $this->data); } 
            }
                else {
                    $this->load->view('login/login_form', $this->data); }
        }
    }
    
    public function logout() {
        $this->login->logout();
        redirect('login'); }
}